<script>
    $(function(){
        update_reparations();
    });
    
    function update_reparations(){
        $.getJSON('app/ajax/ajax_reparations.php?action=liste', function(data) {
            $("#liste_byciclette_hs").html("<thead>"
                +"<tr>"
                +"<td>ID</td>"
                +"<td>Station</td>"
                +"<td>Date</td>"
                +"<td>Id de la byciclette</td>"
                +"<td>Statut</td>"
                +"<td>Actions</td>"
                +"</tr>"
                +"</thead>"
            );
            $.each(data, function(i, item) {
                $("#liste_byciclette_hs").append(
                    "<tr>"
                    +"<td>"+item.id+"</td>"
                    +"<td>"+item.station+"</td>"
                    +"<td>"+item.date+"</td>"
                    +"<td>"+item.id_byciclette+"</td>"
                    +"<td>"+item.statut+"</td>"
                    +"<td><a class=\"btn\" onclick=\"reparer("+item.id+")\">Réparer</a></td>"
                    +"</tr>"
                );
            });
            $('#liste_byciclette_hs').dataTable({
                "bDestroy": true,
                "oLanguage": {
                    "sLengthMenu": "Voir _MENU_ résultats par page",
                    "sZeroRecords": "Aucun résultat trouvé - Désolé",
                    "sInfo": "_START_ - _END_ sur _TOTAL_",
                    "sInfoEmpty": "Showing 0 to 0 of 0 records",
                    "sInfoFiltered": "(filtered from _MAX_ total records)",
                    "oPaginate": {
                        "sFirst": "Premier",
                        "sLast": "Dernier",
                        "sNext": "Suivant",
                        "sPrevious": "Précedent"
                    },
                    "sSearch": "Rechercher"
                }
            });
        });
    }
    
    function reparer(id){
        $.ajax({
            type: 'GET',
            url: 'app/ajax/ajax_reparations.php',
            data: 'action=reparer&id='+id,
            success: function(result){
                //alert(result.toString());
                update_reparations();
            }
        });
    }
</script>
<h1>Liste des byciclettes  HS</h1>
<table id="liste_byciclette_hs" style="width: 100%"></table>